<template>
  <div class="sys_setting_formdata_style">
    <div class="item">
      <p class="title">
        文档设定
      </p>
      <div class="radio_wrp">
        <el-checkbox v-model="data.JE_FILES_HIDEFILES">
          隐藏多附件文件库
        </el-checkbox>
        <el-checkbox v-model="data.JE_FILES_HIDECOMPANYFILES">
          隐藏多附件公司文件库
        </el-checkbox>
        <el-checkbox v-model="data.JE_FILES_HIDEMOVEFILES">
          隐藏多附件移动
        </el-checkbox>
      </div>
    </div>
    <div class="item func">
      <p class="title">
        文库管理员
      </p>
      <el-input
        v-model="data.JE_SYS_DOCADMIN"
        class="hasclick"
        readonly
        clearable
      />
      <i
        @click="handleDocadmin(data.JE_SYS_DOCADMINID)"
        class="jeicon jeicon-syrc"
      />
    </div>
    <div class="item">
      <p class="title">
        文件格式
      </p>
      <div class="table">
        <div class="table_items">
          <div class="w15">
            类型
          </div>
          <div class="w80">
            格式
          </div>
          <div
            @click="add('JE_SYS_DOCFILETYPE')"
            class="w5"
          >
            +
          </div>
        </div>
        <div
          v-for="(item, index) in data.JE_SYS_DOCFILETYPE"
          :key="index"
          class="table_items"
        >
          <div class="w15">
            <el-dropdown @command="handleCommand">
              <span
                @click="choose_item('JE_SYS_DOCFILETYPE', index)"
                class="el-dropdown-link"
                style="cursor: pointer;"
              >
                {{ getCNName(item.code) }}
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item
                  v-for="(choose, i) in dictlist.JE_SYS_DOCFILETYPE"
                  :key="i"
                  :command="choose"
                >
                  {{ choose.text }}
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
          <div class="w80">
            <input
              v-model="item.value"
              type="text"
            >
          </div>
          <div
            @click="del('JE_SYS_DOCFILETYPE', index)"
            class="w5"
          >
            x
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Wdgl',
  props: {
    formdata: {
      type: Object,
      default: () => {},
    },
    dictlist: {
      type: Object,
      default: () => [],
    },
  },
  data() {
    const data = {
      JE_FILES_HIDEFILES: this.formdata.JE_FILES_HIDEFILES,
      JE_FILES_HIDECOMPANYFILES: this.formdata.JE_FILES_HIDECOMPANYFILES,
      JE_FILES_HIDEMOVEFILES: this.formdata.JE_FILES_HIDEMOVEFILES,
      JE_SYS_DOCADMIN: this.formdata.JE_SYS_DOCADMIN,
      JE_SYS_DOCADMINID: this.formdata.JE_SYS_DOCADMINID,
      JE_SYS_DOCFILETYPE: this.formdata.JE_SYS_DOCFILETYPE,
    };
    return {
      click_item: {},
      data,
    };
  },
  methods: {
    add(type) {
      const obj = {
        code: 'office',
        text: '',
        value: '',
      };
      this.formdata[type].push(obj);
    },
    choose_item(type, index) {
      this.click_item.code = type;
      this.click_item.ind = index;
    },
    handleCommand(item) {
      this.data.JE_SYS_DOCFILETYPE[this.click_item.ind].code = item.code;
      this.data.JE_SYS_DOCFILETYPE[this.click_item.ind].text = item.text;
    },
    getCNName(code) {
      if (!code) return;
      const result = this.dictlist.JE_SYS_DOCFILETYPE.filter(item => item.code === code);
      return result.length > 0 && result[0].text;
    },
    del(type, i) {
      this.formdata[type].splice(i, 1);
    },
    handleDocadmin(id) {
      const that = this;
      JE.vue.selectUser({
        title: '文库管理员',
        width: 300,
        height: 500,
        multiple: true,
        configInfo: 'JE_CORE_QUERYUSER,JE_SYS_DOCADMIN~JE_SYS_DOCADMINID,USERNAME~USERID,M',
        otherConfig: JE.toStr({
          DEPT: '1', SENTRY: '1', ROLE: '1', WORKGROUP: '1', QUICKQUERY: 'NONE',
        }),
        value: id,
        valueType: 'id',
        callback(datas) {
          let textarr = '';
          let idarr = '';
          datas.forEach((item) => {
            idarr += `${item.id},`;
            textarr += `${item.text},`;
          });
          idarr = idarr.substring(0, idarr.length - 1);
          textarr = textarr.substring(0, textarr.length - 1);
          that.data.JE_SYS_DOCADMINID = idarr;
          that.data.JE_SYS_DOCADMIN = textarr;
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>

</style>
